package com.qyx.pmpucat.controller;

import com.qyx.pmpucat.common.result.Result;
import com.qyx.pmpucat.common.result.Results;
import com.qyx.pmpucat.entity.OptionCategory;
import com.qyx.pmpucat.service.OptionCategoryService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 选项分类控制器
 */
@RestController
@RequestMapping("/optionCategory")
@RequiredArgsConstructor
@Validated
public class OptionCategoryController {

    private final OptionCategoryService optionCategoryService;

    /**
     * 创建选项分类
     */
    @PostMapping("/create")
    public Result<Long> createOptionCategory(@RequestBody @Valid OptionCategory optionCategory) {
        Long id = optionCategoryService.createOptionCategory(optionCategory);
        return Results.success(id);
    }

    /**
     * 更新选项分类
     */
    @PutMapping("/update")
    public Result<Void> updateOptionCategory(@RequestBody @Valid OptionCategory OptionCategory) {
        optionCategoryService.updateOptionCategory(OptionCategory);
        return Results.success();
    }

    /**
     * 删除选项分类
     */
    @DeleteMapping("/{id}")
    public Result<Void> deleteOptionCategory(@PathVariable Long id) {
        optionCategoryService.deleteOptionCategory(id);
        return Results.success();
    }

    /**
     * 获取选项分类详情
     */
    @GetMapping("/{id}")
    public Result<OptionCategory> getOptionCategoryDetail(@PathVariable Long id) {
        OptionCategory result = optionCategoryService.getOptionCategoryDetail(id);
        return Results.success(result);
    }

    /**
     * 获取所有选项分类列表
     */
    @GetMapping("/all")
    public Result<List<OptionCategory>> getAllOptionCategories() {
        List<OptionCategory> result = optionCategoryService.getAllOptionCategories();
        return Results.success(result);
    }
} 